<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="s" uri="http://www.springframework.org/tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>附件查看</title>
    <jsp:include page="../../head.jsp"/>
</head>
<script type="text/javascript">
    var formSetting = {
        title: "附件操作",
        module: 'query',
        numCount: '2',
        columns: [],
        buttons: {
            custom: []
        },
        grid: {
            id: "dataGrid",
            title: "查询结果",
            <%--url: "attach-findList?filters={\"groupOp\":\"AND\",\"rules\":[{'field':'id','op':'eq','data':'${id}'}]}",--%>
            url: "attach-findList?id=${param.id}",
            colModel: [{
                index: "id",
                name: "id",
                label: "id",
                hidden: true
            }, {
                index: "name",
                name: "name",
                label: "文件名"
            }, {
                index: "ctime",
                name: "ctime",
                formatter: 'date',
                formatoptions: {
                    srcformat: 'Y-m-d H:i:s',
                    newformat: 'Y-m-d H:i:s'
                },
                label: "上传时间"
            }, {
                index: "opa",
                name: "id",
                label: "操作"
            }],
            sortname: "ctime",
            sortorder: "desc",
            jsonReader: {
                // root: "attachments"
            },
            loadComplete: function (data) {
                $("td[aria-describedby='dataGrid_id'][style!='display:none;']")
                        .each(
                                function () {
                                    $(this).html(
                                            '<a target="_blank" href="<s:url value="/business/downloadSingleBizAttachment?atype=${param.type}&aid="/>'
                                            + $(this).text()
                                            + '">查看</a>');
                                })
            }
        }
    };
    $(document).ready(function () {
        $("#dataTable").mrdForm(formSetting);
        $("#mf_buttons_container").empty();
        $("#mf_buttons_container").css("text-align", "left");
        $("#mf_buttons_container").append($("#dialog002"));

        $("form#uploadAccessoryForm").submit(function (e) {
            e.preventDefault();
            var formData = new FormData($(this)[0]);
            $.ajax({
                       url: $(this).attr('action'), // le nom du fichier indiqué dans le formulaire
                       type: $(this).attr('method'), // la méthode indiquée dans le formulaire (get ou post)
                       cache: false,
                       data: formData,
                       contentType: false,
                       processData: false,
                       success: function (data) {
                           if ("undefined" != typeof parent.uploadSuccessBizCallBack) {
                               parent.uploadSuccessBizCallBack(JSON.parse(data).attachment.id)
                           }
                           location.href =
                                   "business/attach-main?id=" + JSON.parse(data).attachment.id
                       }
                   });

            return false;
        });
    });
</script>
<body>
<div id="dataTable"></div>
<div id="dialog002">
    <form id="uploadAccessoryForm" action="/business/attach-upload"
          enctype="multipart/form-data" method="POST">
        <input type="file" label="请" name="attach">
        <input type="submit" value="确认上传">
    </form>
</div>
</body>
</html>
